package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.entity.salary.AwardApplicantEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-08-21 11:22:15
 */
@Mapper
public interface AwardApplicantDao extends BaseMapper<AwardApplicantEntity> {

    @Select("SELECT count(id) FROM tb_award_applicant WHERE inset_date = #{insetDate}")
    Long getAwardApplicantNum(@Param("insetDate")String insetDate);


    @Select(
            "<script> SELECT\n" +
                    "\t* \n" +
                    "FROM\n" +
                    "\t( SELECT taa.*, tap.distribution_status package_status FROM tb_award_applicant taa LEFT JOIN tb_award_package tap ON tap.id = taa.package_id ) tb " +
                    "<where> tb.is_delete = 0 and   (tb.package_status = '1' OR tb.package_status IS NULL)" +
                    "<if test='orgIds!=null and orgIds.size>0'> and tb.org_id in " +
                    " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
                    "</if>"+
                    "<if test='orgIds==null or orgIds.size==0'> and tb.unit_id = null </if>" +

                    "<if test='applicantName!=null'> and tb.applicant_name like '%${applicantName}%' </if>" +
                    "<if test='awardName!=null'> and tb.award_name like '%${awardName}%' </if>" +
                    "<if test='usercode!=null'> and tb.usercode like '%${usercode}%' </if>" +
                    "<if test='startTime!=null'> and tb.create_time &gt;= #{startTime} </if>" +
                    "<if test='endTime!=null'> and tb.create_time &lt;= #{endTime} </if>" +
                    "<if test='approvalStatus!=null'> and tb.approval_status = #{approvalStatus} </if>" +
                    "<if test='approvalStatus==null'> and (tb.approval_status = '0' or tb.approval_status = '1') </if>" +
                    "</where>  order by tb.create_time desc" +
                    "</script>"
    )
    List<AwardApplicantEntity> getAwardApplicantPage( @Param(value = "orgIds") List<Long> orgIds,
                                                      @Param(value = "awardName") String awardName,
                                                 @Param(value = "applicantName") String applicantName,
                                                 @Param(value = "usercode") String usercode,
                                                 @Param(value = "startTime") String startTime,
                                                 @Param(value = "endTime") String endTime,
                                                 @Param(value = "approvalStatus") Integer approvalStatus,
                                                 Page<AwardApplicantEntity> page
    );

}
